import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:my_app/components/a_row/a_row.dart';
import 'package:my_app/components/take_out_btn/index.dart';
import 'package:my_app/custom_swiper/index.dart';

class Home extends StatefulWidget {
  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: <Widget>[
          Stack(
            children: <Widget>[
              Positioned(
                child: CustomSwiper(
                  [
                    'lib/assets/images/home/swiper1.jpg',
                    'lib/assets/images/home/swiper2.jpg',
                    'lib/assets/images/home/swiper3.jpg',
                  ],
                  height: 208 + Get.statusBarHeight,
                ),
              ),
              Positioned(
                top: 50,
                right: 10,
                child: rightChild(
                    icon: Icon(Icons.camera_alt),
                    bgColor: Color.fromRGBO(0, 0, 0, .3),
                    showBorder: false),
              ),
            ],
          ),
          Container(
            color: Colors.white,
            padding: EdgeInsets.symmetric(horizontal: 20),
            child: Column(
              children: <Widget>[
                ARow(
                  height: 70,
                  padding: EdgeInsets.all(0),
                  leftChild: leftChild(
                      title: 'sub way', desc: '距离53m', titleBlod: false),
                  rightChild: TakeOutBtn(),
                ),
                ARow(
                  height: 70,
                  padding: EdgeInsets.all(0),
                  leftChild: leftChild(title: 'order now', desc: 'ORDER NOW'),
                  rightChild: rightChild(
                    icon: Icon(
                      Icons.shopping_bag,
                      color: Color.fromRGBO(99, 71, 58, 1),
                      size: 20,
                    ),
                  ),
                  onPressed: () => {},
                ),
                ARow(
                  height: 70,
                  padding: EdgeInsets.all(0),
                  leftChild:
                      leftChild(title: 'coffe wallet', desc: "COFFE WALLET"),
                  rightChild: rightChild(
                    icon: Icon(
                      Icons.wallet_giftcard,
                      size: 20,
                      color: Color.fromRGBO(104, 68, 60, 1),
                    ),
                  ),
                ),
                ARow(
                  height: 70,
                  padding: EdgeInsets.all(0),
                  leftChild:
                      leftChild(title: 'send coffe', desc: 'SEND COFFEE'),
                  rightChild: rightChild(
                    icon: Icon(Icons.coffee,
                        size: 20, color: Color.fromRGBO(104, 68, 60, 1)),
                  ),
                ),
                ARow(
                  height: 70,
                  padding: EdgeInsets.all(0),
                  leftChild: leftChild(
                      title: 'company account', desc: 'ENTERPRISE ACCOUNT'),
                  rightChild: rightChild(
                    icon: Icon(
                      Icons.article_rounded,
                      size: 20,
                      color: Color.fromRGBO(104, 68, 60, 1),
                    ),
                  ),
                  onPressed: () =>
                      Navigator.pushNamed(context, '/example_widgets_list'),
                ),
                Image.asset('lib/assets/images/home/bottom_bar.png'),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

Widget rightChild({Icon? icon, Color? bgColor, bool showBorder = true}) {
  return Container(
    width: 40,
    height: 40,
    decoration: BoxDecoration(
        color: bgColor,
        border: Border.all(
          color:
              showBorder ? Color.fromRGBO(99, 71, 58, 1) : Colors.transparent,
        ),
        borderRadius: BorderRadius.circular(20)),
    child: Container(
      padding: EdgeInsets.only(left: 2),
      child: icon,
    ),
  );
}

Column leftChild(
    {required String title, required String desc, bool titleBlod = true}) {
  return Column(
    mainAxisAlignment: MainAxisAlignment.center,
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      Row(
        children: [
          Text(
            title,
            style: TextStyle(
              color: Color.fromRGBO(56, 56, 56, 1),
              fontSize: 16,
              fontWeight: titleBlod ? FontWeight.bold : FontWeight.normal,
            ),
          ),
        ],
      ),
      Row(
        children: [
          Text(
            desc,
            style: TextStyle(
              color: Color.fromRGBO(128, 128, 128, 1),
              fontSize: 12,
            ),
          ),
        ],
      ),
    ],
  );
}
